/**
 * UserAction.java
 *2013年10月6日下午10:45:06
 *LINKT
 */
package com.jskj.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.jskj.bean.User;
import com.jskj.commons.BaseAction;
import com.jskj.dao.DaoUser;

/**
 * @author LINKT
 *
 */
public class UserAction extends BaseAction {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        private String page;
        private String start;
        private String limit;
        
        private String swjg_dm;
        private String flogname;
        private String fusername;
        private String fpower;
        private String oldpwd;
        private String newpwd;
        
        
        public void getUserList(){
                HttpServletRequest request=ServletActionContext.getRequest();
                HttpSession session=request.getSession();
                String sql="";
                String sql1="";
                if (swjg_dm==null || swjg_dm.equals("")) {//为空则赋值session中的税务机关
                        swjg_dm=(String)session.getAttribute("swjg_dm");
                }
                if (flogname!=null && !flogname.equals("")) {
                        sql1+=" and a.flogname='"+flogname+"'";
                }
                if (fusername!=null && !fusername.equals("")) {
                        sql1+=" and a.fusername='"+fusername+"'";
                }
                sql="select a.*,b.swjg_mc from teczry a "+
                                "join dm_swjg b on (a.swjg_dm=b.swjg_dm) "+
                                "where a.swjg_dm='"+swjg_dm+"' "+sql1;
                DaoUser daoUser=new DaoUser();
                String str=daoUser.getUserList(Integer.parseInt(page), Integer.parseInt(limit), sql);
                this.out(str);                
                
        }
        public void addUser(){
                User user=new User();
                user.setfLogName(flogname);
                user.setfPassword("88888888");
                user.setfPower(fpower);
                user.setfUserName(fusername);
                user.setSWJG_DM(swjg_dm);
                DaoUser daoUser=new DaoUser();
                if (daoUser.addUser(user)) {
                        this.out("{\"success\":true,\"msg\":\"人员信息添加成功。\"}");
                }else {
                        this.out("{\"success\":false,\"msg\":\"人员信息添加失败,登录名重复。\"}");
                }
        }
        public void modifUser() {
                User user=new User();
                user.setfLogName(flogname);
                user.setfPassword("88888888");
                user.setfPower(fpower);
                user.setfUserName(fusername);
                user.setSWJG_DM(swjg_dm);
                DaoUser daoUser=new DaoUser();
                if (daoUser.modifUser(user)) {
                        this.out("{\"success\":true,\"msg\":\"人员信息修改成功。\"}");
                }else {
                        this.out("{\"success\":false,\"msg\":\"人员信息修改失败,未找到该人员。\"}");
                }
        }
        public void delUser(){
                User user=new User();
                user.setfLogName(flogname);
                user.setfPassword("88888888");
                user.setfPower(fpower);
                user.setfUserName(fusername);
                user.setSWJG_DM(swjg_dm);
                DaoUser daoUser=new DaoUser();
                if (daoUser.delUser(user)) {
                        this.out("{\"success\":true,\"msg\":\"人员信息删除成功。\"}");
                }else {
                        this.out("{\"success\":false,\"msg\":\"人员信息删除失败,未找到该人员。\"}");
                }
        }
        public void changeUserPwd(){
                HttpServletRequest request=ServletActionContext.getRequest();
                HttpSession session=request.getSession();
                DaoUser daoUser=new DaoUser();
                if (daoUser.changeUserPwd((String)session.getAttribute("username"), oldpwd, newpwd)) {
                        this.out("{\"success\":true,\"msg\":\"密码修改成功。\"}");
                }else {
                        this.out("{\"success\":false,\"msg\":\"密码修改失败,原密码不正确。\"}");
                }
        }
        public String getPage() {
                return page;
        }
        public void setPage(String page) {
                this.page = page;
        }
        public String getStart() {
                return start;
        }
        public void setStart(String start) {
                this.start = start;
        }
        public String getLimit() {
                return limit;
        }
        public void setLimit(String limit) {
                this.limit = limit;
        }
        public String getSwjg_dm() {
                return swjg_dm;
        }
        public void setSwjg_dm(String swjg_dm) {
                this.swjg_dm = swjg_dm;
        }
        public String getFlogname() {
                return flogname;
        }
        public void setFlogname(String flogname) {
                this.flogname = flogname;
        }
        public String getFusername() {
                return fusername;
        }
        public void setFusername(String fusername) {
                this.fusername = fusername;
        }
        public String getFpower() {
                return fpower;
        }
        public void setFpower(String fpower) {
                this.fpower = fpower;
        }
        public String getOldpwd() {
                return oldpwd;
        }
        public void setOldpwd(String oldpwd) {
                this.oldpwd = oldpwd;
        }
        public String getNewpwd() {
                return newpwd;
        }
        public void setNewpwd(String newpwd) {
                this.newpwd = newpwd;
        }
}
